import unittest
import requests
import app
from api.login import LoginAPI


class TestLogin(unittest.TestCase):
    def setUp(self):
        # 实例化接口类
        self.login_api = LoginAPI()
        self.session = requests.Session()

    def tearDown(self):
        if self.session:
            self.session.close()

    def test_login(self):
        response = self.login_api.login(self.session, "13800000002", "123456")
        print(response.json())
        self.assertEqual(True, response.json().get('success'))
        self.assertEqual(10000, response.json().get('code'))
        self.assertIn("操作成功", response.json().get('message'))

        app.TOKEN = "Bearer " + response.json().get('data')
        app.headers_data['Authorization'] = app.TOKEN
